﻿@model OPLWeb.Models.MatchSummary
<div id="content-wrapper">
    @if (Model.Team1 != null)
    {
        <div id="content-main">
            <div class="content-main-gutter">
                <table cellspacing="0" cellpadding="0" class="fixtures">
                    <thead>
                        <tr>
                            <th colspan="8" style="text-align: left;">
                                @Model.ThisFixture.Season.SeasonName - @Model.Team1.TeamName V/S @Model.Team2.TeamName
                                <i>[ @Model.ThisFixture.ResultDescription ]</i>
                            </th>
                        </tr>
                    </thead>
                </table>
                <table cellspacing="0" cellpadding="0" class="fixtures">
                    <thead>
                        <tr>
                            <th colspan="8" style="text-align: left;">
                                @Model.Team1.TeamName Batting Summary
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.Team1.Batting)
                        {
                            <tr>
                                <td class="c1">
                                    @item.Player2.Crew.Name
                                </td>
                                <td class="c3">
                                    @{
                            if (item.CaughtBy.HasValue)
                            { 
                                        <text>C</text>
                                                                }
                                    }
                                </td>
                                <td class="c5">
                                    @{
                            if (item.CaughtBy.HasValue)
                            {
                                        <text>@Model.Team2.Players.Where(p => p.ID == item.CaughtBy.Value).FirstOrDefault().Crew.Name</text>
                                                                         
                            }
                            else if (item.RunOutBy.HasValue)
                            {
                                        <text>@Model.Team2.Players.Where(p => p.ID == item.RunOutBy.Value).FirstOrDefault().Crew.Name</text>
                                                                    
                            }
                                    }
                                </td>
                                <td class="c6">
                                    <span class="block-text">@(item.BowledBy.HasValue ? "b" : "")</span>
                                </td>
                                <td class="c5">
                                    @(item.OutBy.HasValue ? item.BowledBy.HasValue ? Model.Team2.Bowling.Where(p => p.PlayerId == item.BowledBy.Value).First().Player2.Crew.Name : "run out" : "not out")
                                </td>
                                <td class="c7">
                                    <ul class="block-text">
                                        <li class="city-score">@item.Run1</li>
                                        <li>
                                            @item.BallsFaced</li>
                                    </ul>
                                </td>
                                <td class="c8">
                                    <a href="javascript:void(0);" class="next">@(item.Run6.HasValue ? item.Run6 + "(6s)" : "")
                                        @(item.Run4.HasValue ? item.Run4 + "(4s)" : "")</a>
                                </td>
                            </tr>
                        }
                        <tr style="color: #5CBFEB;">
                            <td class="c1" style="color: #5CBFEB;">
                                Extras: @(Model.ThisFixture.Team1Score.Value - Model.Team1.Batting.Sum(p => p.Run1))
                            </td>
                            <td class="c3">
                            </td>
                            <td class="c5" style="color: #5CBFEB;">
                                Wickets: @Model.ThisFixture.Team1Wickets
                            </td>
                            <td class="c6">
                            </td>
                            <td class="c5" style="color: #5CBFEB;">
                                Run rate: @((Convert.ToDecimal(Model.ThisFixture.Team1Score.Value) / Model.Team2.Bowling.Sum(p => p.BallsBowled / 6)).Value.ToString("0.00"))
                                per over
                            </td>
                            <td class="c7" style="color: #5CBFEB;">
                                <strong>Total: @Model.ThisFixture.Team1Score</strong>
                            </td>
                            <td class="c8">
                            </td>
                        </tr>
                    </tbody>
                </table>
                <table cellspacing="0" cellpadding="0" class="fixtures">
                    <thead>
                        <tr>
                            <th colspan="8" style="text-align: left;">
                                @Model.Team2.TeamName Bowling Summary
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="c3">
                                Bowler
                            </td>
                            <td class="c3">
                                Overs
                            </td>
                            <td class="c3">
                                Runs
                            </td>
                            <td class="c3">
                                Wickets
                            </td>
                            <td class="c7">
                                Economy
                            </td>
                        </tr>
                        @foreach (var item in Model.Team2.Bowling)
                        {
                            <tr>
                                <td class="c1">
                                    @item.Player2.Crew.Name
                                </td>
                                <td class="c3">
                                    @(item.BallsBowled / 6)
                                </td>
                                <td class="c3">
                                    @item.RunsGiven
                                </td>
                                <td class="c3">
                                    @item.Wickets
                                </td>
                                <td class="c7">
                                    @(Convert.ToDecimal(item.RunsGiven / (item.BallsBowled / 6)))
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
                <table cellspacing="0" cellpadding="0" class="fixtures">
                    <thead>
                        <tr>
                            <th colspan="8" style="text-align: left;">
                                @Model.Team2.TeamName Batting Summary
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.Team2.Batting)
                        {
                            <tr>
                                <td class="c1">
                                    @item.Player2.Crew.Name
                                </td>
                                <td class="c3">
                                    @{
                            if (item.CaughtBy.HasValue)
                            { 
                                        <text>C</text>
                                                                }
                                    }
                                </td>
                                <td class="c5">
                                    @{
                            if (item.CaughtBy.HasValue)
                            {
                                        <text>@Model.Team1.Players.Where(p => p.ID == item.CaughtBy.Value).FirstOrDefault().Crew.Name</text>
                                                                         
                            }
                            else if (item.RunOutBy.HasValue)
                            {
                                        <text>@Model.Team1.Players.Where(p => p.ID == item.RunOutBy.Value).FirstOrDefault().Crew.Name</text>
                                                                    
                            }
                                    }
                                </td>
                                <td class="c6">
                                    <span class="block-text">@(item.BowledBy.HasValue ? "b" : "")</span>
                                </td>
                                <td class="c5">
                                    @(item.OutBy.HasValue ? item.BowledBy.HasValue ? Model.Team1.Bowling.Where(p => p.PlayerId == item.BowledBy.Value).First().Player2.Crew.Name : "run out" : "not out")
                                </td>
                                <td class="c7">
                                    <ul class="block-text">
                                        <li class="city-score">@item.Run1</li>
                                        <li>
                                            @item.BallsFaced</li>
                                    </ul>
                                </td>
                                <td class="c8">
                                    <a href="javascript:void(0);" class="next">@(item.Run6.HasValue ? item.Run6 + "(6s)" : "")
                                        @(item.Run4.HasValue ? item.Run4 + "(4s)" : "")</a>
                                </td>
                            </tr>
                        }
                        <tr style="color: #5CBFEB;">
                            <td class="c1" style="color: #5CBFEB;">
                                Extras: @(Model.ThisFixture.Team2Score.Value - Model.Team2.Batting.Sum(p => p.Run1))
                            </td>
                            <td class="c3">
                            </td>
                            <td class="c5" style="color: #5CBFEB;">
                                Wickets: @Model.ThisFixture.Team2Wickets
                            </td>
                            <td class="c6">
                            </td>
                            <td class="c5" style="color: #5CBFEB;">
                                Run rate: @((Convert.ToDecimal(Model.ThisFixture.Team2Score.Value) / Model.Team1.Bowling.Sum(p => p.BallsBowled / 6)).Value.ToString("0.00"))
                                per over
                            </td>
                            <td class="c7" style="color: #5CBFEB;">
                                <strong>Total: @Model.ThisFixture.Team2Score</strong>
                            </td>
                            <td class="c8">
                            </td>
                        </tr>
                    </tbody>
                </table>
                <table cellspacing="0" cellpadding="0" class="fixtures">
                    <thead>
                        <tr>
                            <th colspan="8" style="text-align: left;">
                                @Model.Team1.TeamName Bowling Summary
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="c3">
                                Bowler
                            </td>
                            <td class="c3">
                                Overs
                            </td>
                            <td class="c3">
                                Runs
                            </td>
                            <td class="c3">
                                Wickets
                            </td>
                            <td class="c7">
                                Economy
                            </td>
                        </tr>
                        @foreach (var item in Model.Team1.Bowling)
                        {
                            <tr>
                                <td class="c1">
                                    @item.Player2.Crew.Name
                                </td>
                                <td class="c3">
                                    @(item.BallsBowled / 6)
                                </td>
                                <td class="c3">
                                    @item.RunsGiven
                                </td>
                                <td class="c3">
                                    @item.Wickets
                                </td>
                                <td class="c7">
                                    @(Convert.ToDecimal(item.RunsGiven / (item.BallsBowled / 6)))
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div> }
    else
    {
        <div id="content-main-feature">
            <img alt="Next games" src="@Url.Content("~/content/images/content-main-feature-image-fixtures.jpg")">
            <div class="cmf-inner">
                <h2 class="white-60">
                    Upcoming Match</h2>
                <ul>
                    <li>
                        <img src="@Url.Content("~/content/icons/256x256/" + @Model.ThisFixture.Team.ID + ".png")"
                        alt="@Model.ThisFixture.Team.TeamName" width="140" height="140">
                        <div class="match-info">
                            <span id="content_0__16ede7bffc03_UpcomingFixtureList_ctl01_TicketStatusInfo" class="soldout">
                            </span>
                            <h3 class="white-24">
                                @Model.ThisFixture.Team.TeamName</h3>
                            <p>
                                Points : @Model.ThisFixture.Team.Points
                            </p>
                            <p class="competition">
                                Owned By : @(string.Join("/", Model.ThisFixture.Team.CrewTeams.Where(p => p.TeamId == Model.ThisFixture.Team.ID).Select(p => p.Crew.Name.Split(' ')[0])))</p>
                            <p class="date">
                                P/W/L : @Model.ThisFixture.Team.Matches / @(Model.ThisFixture.Team.Won.HasValue ? Model.ThisFixture.Team.Won.Value : 0)
                                / @(Model.ThisFixture.Team.Lost.HasValue ? @Model.ThisFixture.Team.Lost.Value : 0)
                            </p>
                        </div>
                    </li>
                    <li>
                        <img src="@Url.Content("~/content/images/versus.png")"
                        alt="Sporting Lisbon" width="140" height="140" />
                        <div class="match-info">
                            <span></span>
                            <h3 class="white-24">
                                Venue</h3>
                            <p>
                                Model Engg College Ground</p>
                            <p class="competition">
                                @Model.ThisFixture.Date.DayOfWeek.ToString()</p>
                            <p class="date">
                                @Model.ThisFixture.Date
                            </p>
                        </div>
                    </li>
                    <li>
                        <img src="@Url.Content("~/content/icons/256x256/" + @Model.ThisFixture.Team1.ID + ".png")"
                        alt="@Model.ThisFixture.Team1.TeamName" width="140" height="140">
                        <div class="match-info">
                            <span id="content_0__16ede7bffc03_UpcomingFixtureList_ctl03_TicketStatusInfo"></span>
                            <h3 class="white-24">
                                @Model.ThisFixture.Team1.TeamName</h3>
                            <p>
                                Points : @Model.ThisFixture.Team1.Points
                            </p>
                            <p class="competition">
                                Owned By : @(string.Join("/", Model.ThisFixture.Team1.CrewTeams.Where(p => p.TeamId == Model.ThisFixture.Team1.ID).Select(p => p.Crew.Name.Split(' ')[0])))</p>
                            <p class="date">
                                P/W/L : @Model.ThisFixture.Team1.Matches / @(Model.ThisFixture.Team1.Won.HasValue ? Model.ThisFixture.Team1.Won.Value : 0)
                                / @(Model.ThisFixture.Team1.Lost.HasValue ? @Model.ThisFixture.Team1.Lost.Value : 0)
                            </p>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    }
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('#nav-main > li').each(function () {
            $(this).removeClass('active');
        });
        $('#results').addClass('active');
        $('#results').show();
    });
</script>
